/**
 * @file test_array_list.c
 * Test file for a generic ArrayList data structure
 * @author Denis Ollier
 * @ingroup Test
 */

#include "test_array_list.h"

void destructor (void* element)
{
}

int comparator (const void* element1, const void* element2)
{
	if (*((int*)element1) < *((int*)element2))
	{
		return -1;
	}
	else if (*((int*)element1) == *((int*)element2))
	{
		return 0;
	}
	else
	{
		return 1;
	}
}

int main (void)
{
	array_list list, clone;
	unsigned int index;

	//test_increment_operator_behaviour();
	//test_int_mult_behaviour();
	//test_free_behaviour();

	list = array_list_new(0, 0, 0.0, comparator, destructor);
	array_list_add_element(list, (void*) 6);
	array_list_add_element_at(list, 0, (void*) 6);
	array_list_add_element_at(list, 0, (void*) 3);
	array_list_add_element_at(list, 0, (void*) 2);
	array_list_add_element_at(list, 0, (void*) 5);
	array_list_add_element_at(list, 0, (void*) 1);
	array_list_add_element_at(list, 0, (void*) 4);
	array_list_add_element_at(list, 0, (void*) 7);
	array_list_add_element_at(list, 0, (void*) 8);
	array_list_remove_range(list, 4,  6);
	printf("Taille de la liste : %d\n", list->size);
	for (index = list->first_index; index < list->first_index + list->size; index++)
		printf("\tElement %d : %d\n", index - list->first_index, (int)list->array[index]);
	clone = array_list_clone(list);
	array_list_quick_sort(clone);
	printf("Taille du clone : %d\n", clone->size);
	for (index = clone->first_index; index < clone->first_index + clone->size; index++)
		printf("\tElement %d : %d\n", index - list->first_index, (int)clone->array[index]);
	array_list_dispose(list);
	array_list_dispose(clone);
	return EXIT_SUCCESS;
}

void test_free_behaviour (void)
{
	int a = 3;
	free((void*)a);
}

void test_increment_operator_behaviour (void)
{
	unsigned int test;

	test = 42;
	printf("Value before int * 1.5 = %u\n", test);
	printf("Value whith int++ = %u\n", test++);
	printf("Value after int++ = %u\n\n", test);

	test = 42;
	printf("Value before ++int = %u\n", test);
	printf("Value whith ++int = %u\n", ++test);
	printf("Value after ++int = %u\n", test);
}

void test_int_mult_behaviour (void)
{
	unsigned int test;

	test = 7;
	printf("Value before int * 1.5 = %u\n", test);
	printf("Value with int * 1.5 = %u\n", (int)(test * 1.5));
	printf("Value with (float) int * 1.5 = %u\n\n", (int)((float)test * 1.5));
}
